// pages/report/report.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: '体检',
    reportObj: {},
    tabdex: "",
    popshow: false,
    page: 0,
    pagesize: 10,
    list: [],
    status: "",
    sick_index: "",
    tablist: [{
      types: "所有人",
      list: [{
          items: "我",
          checked: false
        },
        {
          items: "家庭成员",
          checked: false
        },
        {
          items: "亲戚",
          checked: false
        },
        {
          items: "朋友",
          checked: false
        },
        {
          items: "其他",
          checked: false
        },
      ]
    }, {
      types: "报告类型",
      list: [{
          items: "体检报告",
          checked: false
        },
        {
          items: "基因报告",
          checked: false
        },
        {
          items: "检验报告",
          checked: false
        },
      ]
    }, {
      types: "解读状态",
      list: [{
          items: "未解读",
          checked: false
        },
        {
          items: "已解读",
          checked: false
        },
      ]
    }, ],

    //states 0 检验报告  1  基因报告  2  体检报告
    sicklist: [
      // {
      //   headimg:"../../../images/xzadd.png",
      //   names:"张三",
      //   sex:"男",
      //   age:"23",
      //   times:"2019年12月8日",
      //   hospital:"山西省白求恩医院",
      //   numbers:"8529638525623",
      //   states:0,
      // }, {
      //   headimg: "../../../images/xzadd.png",
      //   names: "张三",
      //   sex: "男",
      //   age: "23",
      //   times: "2019年12月8日",
      //   hospital: "山西省白求恩医院",
      //   numbers: "8529638525623",
      //   states: 1,
      // }, {
      //   headimg: "../../../images/xzadd.png",
      //   names: "张三",
      //   sex: "男",
      //   age: "23",
      //   times: "2019年12月8日",
      //   hospital: "山西省白求恩医院",
      //   numbers: "8529638525623",
      //   states: 2,
      // },
    ],
    tabState: 0
  },
  tabbtn(e) {
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex: ""
      })
    } else {
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex
      })
    }
  },
  itemchecked(e) {
    let arrs = this.data.tablist,
      i = this.data.tabdex,
      dex = e.currentTarget.dataset.dex
    arrs[i].list.map(item => {
      item.checked = false
    })
    arrs[i].types = arrs[i].list[dex].items
    arrs[i].list[dex].checked = true
    this.setData({
      tablist: arrs,
      popshow: false,
      tabdex: ""
    })
  },
  chose_tab: function (e) {
    var index = e.currentTarget.dataset.index;
    if (index == '0') {
      var type = '体检'
    }
    if (index == '1') {
      var type = '基因'
    }
    if (index == '2') {
      var type = '检验'
    }
    var status = this.data.status
    console.log(index, type, status)
    this.setData({
      tabState: index,
      type: type,
      list: []
    })
    wx.showLoading({
      title: '加载中...',
    })
    this.getAlltijianbaogao('', type, '')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this

    if (options.openid) {
      var openid = options.openid
    } else {
      var openid = wx.getStorageSync('openid')
    }

    if (options.zid) {
      that.setData({
        zid: options.zid
      })
    }
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getAlltijianbaogao('', '', '')
  },



  //查看报告
  reportDetailClick: function (e) {
    var that = this
    var id = e.currentTarget.dataset.id;
    if (that.data.zid) {
      var ifzj = 1
    } else {
      var ifzj = 0
    }
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/diagReport/diagReport?id=' + id + '&ifzj=' + ifzj,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var sick_index = that.data.sick_index;
    var type = that.data.type;
    var status = that.data.status;
    that.getAlltijianbaogao(sick_index, type, status);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //查询我的所有体检报告
  getAlltijianbaogao: function (sick_index, type, status) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/user.tijianjiedu',
      data: {
        openid: that.data.openid,
        sick_index: sick_index,
        status: status,
        type: type,
        page: that.data.page,
        pagesize: that.data.pagesize,
      },
      success: function (res) {

        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data)
        })
        wx.hideLoading()
      }
    })
  },

})